package com.sm.graduation.echarts.service.impl;

import com.sm.graduation.common.result.AjaxResult;
import com.sm.graduation.dormitory.dao.DormitoryAllocationMapper;
import com.sm.graduation.echarts.dto.Biscuits;
import com.sm.graduation.echarts.dto.Pillar;
import com.sm.graduation.echarts.service.EchartsService;
import com.sm.graduation.visitor.dao.VisitorMapper;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EchartsServiceImpl implements EchartsService {


    @Resource
    private VisitorMapper visitorMapper;


    @Resource
    private DormitoryAllocationMapper dormitoryAllocationMapper;


    @Override
    public AjaxResult getEchats() {
        Map<String, Object> map = new HashMap<>();
        // 计算全部的数量

        LocalDate now = LocalDate.now();
        String star = now.with(TemporalAdjusters.firstDayOfMonth()).toString();
        String end = now.with(TemporalAdjusters.lastDayOfMonth()).toString();


        Long count1 = dormitoryAllocationMapper.selectCount1();
        Long count2 = dormitoryAllocationMapper.selectCount2(star, end);
        Long count3 = dormitoryAllocationMapper.selectCount3();
        Long count4 = dormitoryAllocationMapper.selectCount4(star, end);
        map.put("count1", count1);
        map.put("count2", count2);
        map.put("count3", count3);
        map.put("count4", count4);


        // 计算饼图

        List<Biscuits> table1 = dormitoryAllocationMapper.table1();
        List<Biscuits> table3 = dormitoryAllocationMapper.table3();
        map.put("table1", table1);
        map.put("table3", table3);


//
//        // 计算柱状图


        List<Biscuits> table2 = dormitoryAllocationMapper.table2();
        Pillar pillar2 = Pillar.covertToP(table2);
        map.put("table2", pillar2);

        List<Biscuits> table4 = dormitoryAllocationMapper.table4();
        Pillar pillar4 = Pillar.covertToP(table4);
        map.put("table4", pillar4);


        return AjaxResult.successData(1, map);
    }
}
